﻿Imports System.IO

Public Class FileHelper
    ''' <summary>
    ''' This function is used to retrieve 
    ''' </summary>
    ''' <param name="folderPath"> String - Indicate the Folder Path which is going to read the files/folder</param>
    ''' <param name="includeSubDirectories">Boolean to indicate whether it should read the subfolder</param>
    ''' <returns> Array of FileInfo Object</returns>
    ''' <remarks></remarks>
    Public Function GetAllFilesOnTheDirectory(ByVal folderPath As String, ByVal includeSubdirectories As Boolean) As FileInfo()
        'Create a 
        Dim FileLists As New List(Of FileInfo)
        Dim dirInfo As New DirectoryInfo(folderPath)
        FileLists.AddRange(dirInfo.GetFiles)
        If includeSubdirectories Then
            Dim DirList() As DirectoryInfo = dirInfo.GetDirectories
            For i As Integer = 0 To DirList.Length - 1
                FileLists.AddRange(GetAllFilesOnTheDirectory(DirList(i).FullName, includeSubdirectories))
            Next
        End If
        Return FileLists.ToArray
    End Function



End Class
